﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QUAN_LY_MUON_TRA_SACH
{
    public partial class frmsaoluu : Form
    {
        public frmsaoluu()
        {
            InitializeComponent();
        }
       
        private void frmsaoluu_Load(object sender, EventArgs e)
        {
            cbocsdl.Focus();
            DataTable bangtenCSDL = new DataTable();
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select name, create_date from sys.databases", Connection.sqlConnection);
            sqlDataAdapter.Fill(bangtenCSDL);
            cbocsdl.DataSource = bangtenCSDL;
            cbocsdl.ValueMember = "name";
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnthuchien_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title = "Chọn đường dẫn và tên file sao lưu";
            saveFileDialog1.Filter = "Backup Files(*.bak)|*.bak|All Files(*.*)|*.*";
            saveFileDialog1.FileName = "sao lưu";
            if(saveFileDialog1.ShowDialog()==DialogResult.OK)
            try
            {
                SqlCommand lenh = new SqlCommand("backup database "+cbocsdl.Text+" to disk='"+saveFileDialog1.FileName+"'" , Connection.sqlConnection);
                
                int n = lenh.ExecuteNonQuery();
                
                lenh.Dispose();
                MessageBox.Show("Sao lưu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: "+ex.Message);
            }
        }
    }
}
